package com.yipei.business.controller;

import com.yipei.business.domain.MlRealName;
import com.yipei.business.service.IMlRealNameService;
import com.yipei.common.annotation.Log;
import com.yipei.common.core.controller.BaseController;
import com.yipei.common.core.domain.AjaxResult;
import com.yipei.common.core.page.TableDataInfo;
import com.yipei.common.enums.BusinessType;
import com.yipei.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 实名认证Controller
 *
 * @author yipei
 * @date 2024-12-21
 */
@RestController
@RequestMapping("/business/name")
@Api(tags = "实名认证", description = "实名认证管理")
public class MlRealNameController extends BaseController {
    @Autowired
    private IMlRealNameService mlRealNameService;

    /**
     * 查询实名认证列表
     */
    //@PreAuthorize("@ss.hasPermi('business:name:list')")
    @ApiOperation("实名认证获取数据")
    @GetMapping("/list")
    public TableDataInfo list(MlRealName mlRealName) {
        startPage();
        List<MlRealName> list = mlRealNameService.selectMlRealNameList(mlRealName);
        return getDataTable(list);
    }

    /**
     * 导出实名认证列表
     */
    //@PreAuthorize("@ss.hasPermi('business:name:export')")
    @ApiOperation("实名认证导出数据")
    @Log(title = "实名认证", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MlRealName mlRealName) {
        List<MlRealName> list = mlRealNameService.selectMlRealNameList(mlRealName);
        ExcelUtil<MlRealName> util = new ExcelUtil<MlRealName>(MlRealName.class);
        util.exportExcel(response, list, "实名认证数据");
    }

    /**
     * 获取实名认证详细信息
     */
    //@PreAuthorize("@ss.hasPermi('business:name:query')")
    @ApiOperation("实名认证通过ID获取数据")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(mlRealNameService.selectMlRealNameById(id));
    }

    /**
     * 新增实名认证
     */
    //@PreAuthorize("@ss.hasPermi('business:name:add')")
    @ApiOperation("·")
    @Log(title = "实名认证", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody MlRealName mlRealName) throws Exception {
        return toAjax(mlRealNameService.insertMlRealName(mlRealName));
    }

    /**
     * 修改实名认证
     */
    //@PreAuthorize("@ss.hasPermi('business:name:edit')")
    @ApiOperation("实名认证修改数据")
    @Log(title = "实名认证", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MlRealName mlRealName) {
        return toAjax(mlRealNameService.updateMlRealName(mlRealName));
    }

            /**
     * 删除实名认证
     */
    //@PreAuthorize("@ss.hasPermi('business:name:remove')")
    @ApiOperation("实名认证删除数据")
    @Log(title = "实名认证", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mlRealNameService.deleteMlRealNameByIds(ids));
    }

    @ApiOperation("实名认证获取数据,status： 1 实名审核,2 实名成功，3 实名失败")
    @GetMapping("/getIsRealName")
    public AjaxResult getIsRealName() {
        MlRealName mlRealName= mlRealNameService.getIsRealName();
        return AjaxResult.success(mlRealName);
    }
}
